package com.angcyo.selenium.auto.action

import com.angcyo.library.ex.getLongNumList
import com.angcyo.selenium.auto.BaseControl
import com.angcyo.selenium.auto.findAction
import com.angcyo.selenium.auto.parse.HandleResult
import com.angcyo.selenium.bean.ActionBean
import org.openqa.selenium.WebElement

/**
 * Email:angcyo@126.com
 * @author angcyo
 * @date 2021-1-13
 */
class EnableAction : BaseAction() {

    override fun interceptAction(control: BaseControl, action: String?): Boolean {
        return action?.startsWith(Action.ACTION_ENABLE) == true
    }

    override fun runAction(
        control: BaseControl,
        element: WebElement,
        actionBean: ActionBean,
        action: String
    ): HandleResult {
        val result = HandleResult()
        result.elementList = listOf(element)

        val enableIdList = mutableListOf<Long>()
        action.getLongNumList(true)?.forEach { id ->
            val findAction = control.findAction(id)
            findAction?.let {
                enableIdList.add(it.actionId)
                it.enable = true
                result.success = true
            }
        }
        control.logAction?.invoke("激活Action[${enableIdList}]:${result.success}")
        return result
    }
}